import router from '@/router/index'
import store from '@/store/index'

router.beforeEach((to, from, next) => {
  const token = store.state.user.token
  const whiteList = ['/404', '/login']
  console.log(to.path)
  if (token && to.path === '/login') {
    next('/')
    console.log('有token，去登录页')
  }
  if (token && to.path !== '/login') {
    next()
    console.log('有token，不是去登录页')
  }
  if (!token && whiteList.indexOf(to.path) !== -1) {
    next()
    console.log('无token，白名单')
  }
  if (!token && whiteList.indexOf(to.path) === -1) {
    next('/login')
    console.log('无token，不在白名单')
  }
})
